package com.jqh.openglesdemo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.jqh.openglesdemo.muti.JqhMutiSurfaceView;
import com.jqh.openglesdemo.shader.JqhGLTextureView;
import com.jqh.openglesdemo.shader.JqhTextureRender;

public class JqhTextureActivity extends AppCompatActivity {

    private JqhGLTextureView jqhGLTextureView;

    private LinearLayout lyContent;

    private int[] fragmentShaderIds = {
            R.raw.fragment_shader1,
            R.raw.fragment_shader3,
            R.raw.fragment_shader2
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_jqh_texture);

        jqhGLTextureView = findViewById(R.id.jqhGLTextureView);
        lyContent = findViewById(R.id.ly_container);

        jqhGLTextureView.getJqhTextureRender().setOnRenderCreateListener(new JqhTextureRender.OnRenderCreateListener() {
            @Override
            public void onCreate(final int textureId) {
                // 获取纹理id
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if(lyContent.getChildCount() >0) {
                            lyContent.removeAllViews();
                        }
                       for(int i = 0 ; i < 3; i++) {
                           JqhMutiSurfaceView jqhMutiSurfaceView = new JqhMutiSurfaceView(JqhTextureActivity.this);
                           jqhMutiSurfaceView.setTextureId(textureId,fragmentShaderIds[i]);
                           jqhMutiSurfaceView.setSurfaceAndEglContext(null, jqhGLTextureView.getEglContext());
                           LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
                           layoutParams.width = 300;
                           jqhMutiSurfaceView.setLayoutParams(layoutParams);
                           lyContent.addView(jqhMutiSurfaceView);
                       }
                    }
                });
            }
        });
    }
}
